package org.example.novel.web;

import org.example.novel.annotation.Anonymous;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
import static org.example.novel.constant.NovelConstant.*;

@RestController
@RequestMapping(NOVEL_API)
public class NovelController {

    @Anonymous
    @RequestMapping(value = GET_NOVEL,method = RequestMethod.GET)
    public Object get() throws IOException {
        Document parse = Jsoup.connect("https://www.qimao.com/shuku/1747899-16968506990002/").get();
        System.out.println(parse);

        Elements elementsByClass = parse.body().getElementsByClass("chapter-title");
        System.out.println("==========文章标题==========");
        System.out.println(elementsByClass.html());

        Elements article = parse.body().getElementsByClass("article");
        System.out.println("==========文章内容==========");
        System.out.println(article.html());
        return article.html();
    }

}
